define(["jquery", "easy-admin"], function ($, ea) {

    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        index_url: 'user.envelopes/index',
        delete_url: 'user.envelopes/delete',
    };

    var Controller = {

        index: function () {

            ea.table.render({
                init: init,
                defaultToolbar:['filter', {
                    title: '搜索',
                    layEvent: 'TABLE_SEARCH',
                    icon: 'layui-icon-search',
                    extend: 'data-table-id="' + 'user_group' + '"'
                }],
                toolbar:['refresh'],
                cols: [[
                    {type: "checkbox"},
                    {field: 'username', minWidth: 80, title:'发送人',search:false},
                    {field: 'roomid', minWidth: 80, title: '房间号'},
                    {field: 'price', minWidth: 80, title: '金额'},
                    {field: 'number', minWidth: 80, title: '个数'},
                    {field: 'surplus_price', minWidth: 80, title: '余额'},
                    {field: 'surplus_number', minWidth: 80, title: '余数'},
                    {
                        field: 'is_forbid',
                        title: '操作',
                        templet: function (e) {
                            let html = ''
                            html += `<a class="layui-btn layui-btn-success layui-btn-xs" data-open="user.envelopes/record?id=${e.id}" data-title="红包情况">红包情况</a>`
                            html += `<a class="layui-btn layui-btn-danger layui-btn-xs" data-request="user.envelopes/delete?id=${e.id}" data-title="确定删除？">删除</a>`
                            return html;
                        }
                    },
                ]],
            });

            ea.listen();
        },
        record: function () {
            var initrecord = {
                table_elem: '#currentTable',
                table_render_id: 'currentTableRenderId',
                index_url: 'user.envelopes/record',
            };
            ea.table.render({
                init: initrecord,
                defaultToolbar:[],
                toolbar:['refresh'],
                cols: [[
                    {field: 'username', minWidth: 80, title:'用户名',search:false},
                    {field: 'price', minWidth: 80, title: '金额'},
                    {field: 'create_time', minWidth: 80, title: '时间'}
                ]],
            });
            ea.listen();
        },
       
    };
    return Controller;
});